﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;
using BaBaoFan.Modifier.Model;
using BaBaoFan.Modifier.Service;
using Microsoft.AspNetCore.Mvc;
using Microsoft.Extensions.Caching.Memory;

namespace BaBaoFan.Modifier.Controllers
{
    public class MillInfoController : BaseController
    {
        private readonly IMillInfoService _millInfoService;
        public MillInfoController(IMillInfoService millInfoService, IMemoryCache memoryCache) : base(memoryCache)
        {
            _millInfoService = millInfoService;
        }
        public IActionResult List()
        {
            var millInfos = _millInfoService.GetMillInfos();
            return View(millInfos);
        }
        public IActionResult Delete(int[] ids)
        {
            _millInfoService.Delete(ids);
            return Json("ok");
        }
        [HttpPost]
        public IActionResult Add(MillInfo model)
        {
            if (!ModelState.IsValid)
                return View(model);
            _millInfoService.Add(model);
            return Redirect("/MillInfo/List");
        }
        [HttpGet]
        public IActionResult Add()
        {
            return View();
        }
        [HttpGet]
        public IActionResult Edit(int id)
        {
            var model = _millInfoService.GetMillById(id);
            return View(model);
        }
        [HttpPost]
        public IActionResult Update(MillInfo model)
        {
            if (!ModelState.IsValid)
                return View(model);
            _millInfoService.Update(model);
            return Redirect("/MillInfo/List");
        }
    }
}